<template>
  <!-- 问卷调查 输入框 -->
  <div>
    <el-row>
      <p class="title">{{title}}</p>
      <el-form ref="form" :model="form" label-width="180px">
        <el-form-item label="标题" prop="questionnaire_title" :rules="filter_rules({required:true})">
          <el-input placeholder="请输入标题" style="width: 400px;" v-model="form.questionnaire_title">
          </el-input>
        </el-form-item>
      </el-form>
    </el-row>
  </div>
</template>

<script>
import { toSimplifiedChinese } from "@/utils";

export default {
  name: "singleTemp",
  props: {
    index: Number,
    inNum: Number,
    entryobj:Object
  },
  computed: {
    title(){
      return '【输入题' + toSimplifiedChinese(this.index + 1) + '】';
    }
  },
  data() {
    return {
      form: {},
      options: [{ name: "选项一" }]
    };
  },
  methods: {
    async validate() {
      let flag = false;
      this.$refs["form"].validate(valid => {
        flag = valid;
        if (!valid) {
          return false;
        }
      });
      return flag;
    },
    async getData() {
      const result = {
        questionnaire_sort: this.inNum,
        questionnaire_title: this.form.questionnaire_title,
        question_type: 4
      };
      result.questionnaireOptions = this.options.map((_, i) => {
        return { questionnaire_option: this.form[i] };
      });
      return result;
    }
  },
  created () {
    if (this.$route.query.name == "edit") {
      this.form.questionnaire_title = this.entryobj.questionnaire_title;
      if (this.entryobj.questionnaireOptions) {
        this.entryobj.questionnaireOptions.forEach((item, i) => {
          this.form[i] = item.questionnaire_option;
          this.options.push({
            name: "选项" + toSimplifiedChinese(this.options.length + 1)
          });
        });
        this.options.pop();
      }
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.title {
  padding: 0 0 10px;
}


</style>
